import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class E06_SleepingTask {
	public static void main(String[] args) {
		ExecutorService exec = Executors.newCachedThreadPool();
		for (int i = 0; i < 10; i++) {
			exec.execute(new SleppingTask());
		}
		exec.shutdown();
	}

}

class SleppingTask implements Runnable {

	private static int taskCount = 0;
	private final int id = taskCount++;
	private static Random rand = new Random(47);

	@Override
	public void run() {
		int sleepTime = rand.nextInt(10)+1;
		try {
			TimeUnit.SECONDS.sleep(sleepTime);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("#(" + id + ") sleep time  " + sleepTime + "s");
	}

}
